#include "../include/kc.h"
#include "../include/defs.h"

/**************************************************************************/

void setup_IDT_entry (DESCR_INT *item, byte selector, dword offset, byte access,
			 byte cero) {
  item->selector = selector;
  item->offset_l = offset & 0xFFFF;
  item->offset_h = offset >> 16;
  item->access = access;
  item->cero = cero;
}


/**************************************************************************/

int
strlen(char * cadena)
{
	int i;
	for(i=0;cadena[i]!='\0';i++)
	{
	}
	return i;
}

/**************************************************************************/

int
strcmp(char* s,char* t)
{
		int i;
		for(i=0;s[i]==t[i];i++)
		{
			if(s[i]=='\0')
				return 0;
		}
		return s[i]-t[i];
}

/**************************************************************************/

//Memcopy
void memcpy2(char* a, char* b, int len)
{
	int i;
	for(i = 0; i < len; i++)
	{
		a[i] = b[i];
	}
	return;
}

//Compara memoria
int memcmp(char* a, const char* b, int len)
{
	int i;
	for(i = 0; i < len; i++)
	{
		if (a[i] != b[i])
		{
			return 0;
		}
	}
	return 1;
}

//Integer to String
int itoa2(unsigned int a, char* rta)
{
	char temp;
	int contador = 0;
	int i;
	
	do
	{
		rta[contador] = (a % 10) + 0x30;
		a /= 10;
		contador++;
	}
	while (a!=0);
	for(i = 0; i < (contador / 2); i++)
	{
		temp = rta[i];
		rta[i] = rta[contador - i - 1];
		rta[contador - i - 1] = temp;
	}
	rta[contador]=0;
	return contador;	
}

//Longitud de un string
int strlen2(char* a)
{
	int i;
	for(i = 0; i < 80; i++)
	{
		if(a[i] == '\0')
		{
			return i;
		}
	}
	return -1;
}

//Memcopy pensado para copiar de un buffer a video
void memcpy3(char* a, char* b, int len)
{
	int i;
	for(i = 0; i < len; i++)
	{
		a[2 * i] = b[i];
	}
	return;
}